/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Panel_Video.java
 *
 * Created on 10-may-2013, 3:20:11
 */
package jumavidesktop.GUI.Principal;

import java.awt.BorderLayout;
import java.lang.String;
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import jumavidesktop.Manejadores.Implementaciones.ControlMCamaras;
import jumavidesktop.Manejadores.Implementaciones.MCamara;
import jumavidesktop.Manejadores.Intefaces.INotificadoMatricula;
import jumavidesktop.Manejadores.Intefaces.INotificadoVideo;
import jumavidesktop.Persistencia.entidades.Camara;
import jumavidesktop.Persistencia.entidades.Movimientos;

/**
 *
 * @author kjh
 */
public class Panel_Video extends javax.swing.JInternalFrame implements INotificadoVideo, INotificadoMatricula{
    private ControlMCamaras camaras;
    /** Creates new form Panel_Video */
        public Panel_Video(ControlMCamaras camaras) {
        super("Ventana de Vídeo");
        initComponents();
        this.setVisible(true);
        this.camaras = camaras;
        initBoton();
        this.botonBarrera.setEnabled(false);
        initComboBox();
        borrarTodo();
        quitarIconos();
        //lo bloqueo en la parte superior del desktoppane.
        BasicInternalFrameTitlePane titlePane = (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) this.getUI()).getNorthPane();  
        this.remove(titlePane); 
        
    }

    private void quitarIconos(){
        this.setIconifiable(false);
        this.setMaximizable(false);
        this.setClosable(false);
        this.setResizable(true);
        this.setVisible(true);
    }
    public void actualizarPanelIzq(){
        if(jComboBox1.getSelectedItem()!=null){
            String selec = (String) this.jComboBox1.getSelectedItem();
            Camara camara = camaras.getMCamara(selec).getCamara();
            this.setLabNombreDato(camara.getNombre());
            this.setLabFuncionDato(camara.getTipoCamara().toString().toLowerCase());
            if(camara.isActivo())
                this.setLabEstadoDato("capturando");
            else{
                this.setLabEstadoDato("preparada");
            }
                this.setLabFuenteDato(camara.getConfigdetectionmotion().getTipoRecurso().toString().toLowerCase());
            }
    }
    
    public void borrarTodo(){
        jComboBox1.setSelectedIndex(-1);
        this.setLabEstadoDato("");
        this.setLabFuenteDato("");
        this.setLabFuncionDato("");
        this.setLabNombreDato("");
    }
    
    public void initComboBox(){
        jComboBox1.removeAllItems();
        jComboBox1.setSelectedIndex(-1);
        Iterator<String> iterador = camaras.getNombresCamaras().iterator();
        while(iterador.hasNext()){
            this.jComboBox1.addItem((String) iterador.next());
        }
        repintar();
    }
    
    public void initBoton(){
        jButton1.setFocusPainted(false);
        jButton1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
    }
    
    public void pintarBoton(boolean encendido){
        if(encendido){
            //pongo icono verde al boton.
            ImageIcon tmpIconAux = new ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/verde.png"));
            ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage());
            jButton1.setIcon(tmpIcon); 
            
            //pongo icono verde cuando se haga rollover.
            ImageIcon tmpIconAux2 = new ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/verderoll.png"));
            ImageIcon tmpIcon2 = new ImageIcon(tmpIconAux2.getImage());
            jButton1.setRolloverIcon(tmpIcon2); 
        }else{
            //pongo icono rojo al boton.
            ImageIcon tmpIconAux = new ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/rojo.png"));
            ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage());
            jButton1.setIcon(tmpIcon); 
            
            //pongo icono rojo cuando se haga rollover.
            ImageIcon tmpIconAux2 = new ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/rojor.png"));
            ImageIcon tmpIcon2 = new ImageIcon(tmpIconAux2.getImage());
            jButton1.setRolloverIcon(tmpIcon2);             
        }
    }

    public void setLabEstadoDato(String labEstadoDato) {
        this.labEstadoDato.setText(labEstadoDato);
    }

    public void setLabFuenteDato(String labFuenteDato) {
        this.labFuenteDato.setText(labFuenteDato);
    }

    public void setLabFuncionDato(String labFuncionDato) {
        this.labFuncionDato.setText(labFuncionDato);
    }

    public void setLabNombreDato(String labNombreDato) {
        this.labNombreDato.setText(labNombreDato);
    }
    
    public JPanel getPanelDer(){
        return this.panelDer;
    }
    
  
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        panelIzq = new javax.swing.JPanel();
        panelSup = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        labNombre = new javax.swing.JLabel();
        labNombreDato = new javax.swing.JLabel();
        labFuncion = new javax.swing.JLabel();
        labFuncionDato = new javax.swing.JLabel();
        labEstado = new javax.swing.JLabel();
        labEstadoDato = new javax.swing.JLabel();
        labFuente = new javax.swing.JLabel();
        labFuenteDato = new javax.swing.JLabel();
        botonBarrera = new javax.swing.JButton();
        panelDer = new javax.swing.JPanel();

        setPreferredSize(new java.awt.Dimension(560, 360));

        panelSup.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Selección de Cámara", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jComboBox1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jComboBox1FocusGained(evt);
            }
        });

        javax.swing.GroupLayout panelSupLayout = new javax.swing.GroupLayout(panelSup);
        panelSup.setLayout(panelSupLayout);
        panelSupLayout.setHorizontalGroup(
            panelSupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBox1, 0, 159, Short.MAX_VALUE)
        );
        panelSupLayout.setVerticalGroup(
            panelSupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSupLayout.createSequentialGroup()
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cámara Actual", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/rojo.png"))); // NOI18N
        jButton1.setBorder(null);
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/rojor.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel1.setText("ACTIVAR CÁMARA");

        labNombre.setFont(new java.awt.Font("Tahoma", 1, 11));
        labNombre.setText("Nombre:");

        labNombreDato.setText("Camara Patio");

        labFuncion.setFont(new java.awt.Font("Tahoma", 1, 11));
        labFuncion.setText("Funcion:");
        labFuncion.setPreferredSize(new java.awt.Dimension(47, 14));

        labFuncionDato.setText("Entrada");

        labEstado.setFont(new java.awt.Font("Tahoma", 1, 11));
        labEstado.setText("Estado:");
        labEstado.setPreferredSize(new java.awt.Dimension(47, 14));

        labEstadoDato.setText("Capturando");

        labFuente.setFont(new java.awt.Font("Tahoma", 1, 11));
        labFuente.setText("Fuente:");
        labFuente.setPreferredSize(new java.awt.Dimension(47, 14));

        labFuenteDato.setText("Video");

        botonBarrera.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jumavidesktop/recursos/iconos/barrera.jpg"))); // NOI18N
        botonBarrera.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botonBarrera.setMaximumSize(new java.awt.Dimension(125, 31));
        botonBarrera.setMinimumSize(new java.awt.Dimension(127, 31));
        botonBarrera.setPreferredSize(new java.awt.Dimension(125, 31));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labFuente, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labFuenteDato, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labNombreDato, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labEstadoDato, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labFuncion, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19)
                        .addComponent(labFuncionDato, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(23, 23, 23)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(botonBarrera, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(botonBarrera, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labNombre)
                    .addComponent(labNombreDato))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labFuncion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labFuncionDato, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labEstadoDato))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labFuente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labFuenteDato)))
        );

        javax.swing.GroupLayout panelIzqLayout = new javax.swing.GroupLayout(panelIzq);
        panelIzq.setLayout(panelIzqLayout);
        panelIzqLayout.setHorizontalGroup(
            panelIzqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelIzqLayout.createSequentialGroup()
                .addComponent(panelSup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(panelIzqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelIzqLayout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        panelIzqLayout.setVerticalGroup(
            panelIzqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelIzqLayout.createSequentialGroup()
                .addComponent(panelSup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(281, Short.MAX_VALUE))
            .addGroup(panelIzqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelIzqLayout.createSequentialGroup()
                    .addGap(60, 60, 60)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        panelDer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panelDer.setPreferredSize(new java.awt.Dimension(570, 360));
        panelDer.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 550, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(panelIzq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(panelDer, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 336, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panelDer, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
                .addComponent(panelIzq, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    MCamara aux;
    if(jComboBox1.getSelectedItem()!=null){        
        aux=this.camaras.getMCamara((String) this.jComboBox1.getSelectedItem());
        if(!aux.getCamara().isActivo()){
            this.panelDer.removeAll();
            this.panelDer.add(aux.getPanelVideo(),BorderLayout.CENTER);
            aux.getCamara().setActivo(true);
            this.pintarBoton(true);
            Thread hilo = new Thread(aux);
            hilo.start();
            repintar();
        }
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void repintar(){
    this.repaint();
    this.updateUI();
}

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    this.actualizarPanelIzq();
    //si hay alguna cámara seleccionada, actualizo paneles.
    if(jComboBox1.getSelectedIndex()>=0){
        MCamara aux=this.camaras.getMCamara((String) this.jComboBox1.getSelectedItem());
        this.panelDer.removeAll();
        this.panelDer.add(aux.getPanelVideo(),BorderLayout.CENTER);
        //si está desactivada pinto rojo, y si no pinto verde.
        if(!aux.getCamara().isActivo()){
           this.pintarBoton(false); 
           aux.getCamara().setActivo(false);
        }else{
            this.pintarBoton(true);
        }
        repintar();
    }
//    if(!aux.getCamara().isActivo()){
//       // this.pintarBoton(S);
//    }
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jComboBox1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jComboBox1FocusGained

}//GEN-LAST:event_jComboBox1FocusGained

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonBarrera;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel labEstado;
    private javax.swing.JLabel labEstadoDato;
    private javax.swing.JLabel labFuente;
    private javax.swing.JLabel labFuenteDato;
    private javax.swing.JLabel labFuncion;
    private javax.swing.JLabel labFuncionDato;
    private javax.swing.JLabel labNombre;
    private javax.swing.JLabel labNombreDato;
    private javax.swing.JPanel panelDer;
    private javax.swing.JPanel panelIzq;
    private javax.swing.JPanel panelSup;
    // End of variables declaration//GEN-END:variables

    @Override
    public void updateCam(Camara cam, boolean llave) {
        if(llave){
            this.jComboBox1.addItem((String) cam.getNombre());
        }
        else{
            this.jComboBox1.removeItem((String) cam.getNombre());
        }
    }

    @Override
    public void detectadaMatricula(Movimientos mv) {
        new Thread(){
            public void run(){
                botonBarrera.setEnabled(false);
                System.out.println("ha entrado");
                int cont=0;
                while(cont<15){
                    try {
                        Thread.sleep(300);
                        botonBarrera.setEnabled(!botonBarrera.isEnabled());
                        cont++;
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    
                }
                botonBarrera.setEnabled(false);
            }
        }.start();
        
    }
}
